# encoding: utf-8
import os
import sys
import platform


def create_file(file_name):
    if not os.path.exists(file_name):
        os.makedirs(file_name)

'''
swagger 参数
'''
ADD_SPECS = True
LOG_OPTION = True

'''
模型地址
'''
MODEL_BASE_PATH = r'D:\contract\models' if platform.system() == 'Windows' else r'/app/contract/models'

'''
错字提取模型
nlp_bart_text-error-correction_chinese-law 显存占用大, 效果最好, 预测时间长, 结果需要二次处理
macbert4csc-base-chinese 显存占用小, 效果一般, 预测时间快
'''
ASSIST_ERROR_CORRECTION_MODEL_NAME = 'nlp_bart_text-error-correction_chinese-law'
ASSIST_ERROR_CORRECTION_MODEL_PATH = os.path.join(MODEL_BASE_PATH, ASSIST_ERROR_CORRECTION_MODEL_NAME)
ERROR_INTERSECT_CORRECTION = False
ERROR_CORRECTION_MODEL_NAME = 'CQU'
ERROR_CORRECTION_MODEL_PATH = os.path.join(MODEL_BASE_PATH, ERROR_CORRECTION_MODEL_NAME)
ERROR_IGNORE_DEL = True

'''
要素提取model相关参数
'''
ORIGIN_MODEL_NAME = r'nlp_deberta_rex-uninlu_chinese-base'
ORIGIN_TASK = 'rex-uninlu'
ORIGIN_MODEL_PATH = MODEL_BASE_PATH + '//' + ORIGIN_MODEL_NAME

MODEL_SAVE_PATH = r'D:\contract\save_models' if platform.system() == 'Windows' else r'/app/contract/save_models'
create_file(MODEL_SAVE_PATH)

MODEL_TRAIN_PATH = r'D:\contract\train_models' if platform.system() == 'Windows' else r'/app/contract/train_models'
create_file(MODEL_TRAIN_PATH)

MODEL_TRAIN_DATA_PATH = r'D:\contract\train_data' if platform.system() == 'Windows' else r'/app/contract/train_data'
create_file(MODEL_TRAIN_DATA_PATH)
'''
数据输出地址
'''
TRAIN_TEST_DATA = r'D:\models\contract\data\test_data' if platform.system == 'Windows' else r'/app/contract/data/test_data'
create_file(TRAIN_TEST_DATA)


'''
log地址
'''
LOG_BASE_PATH = r'D:/contract/logs' if platform.system() == 'Windows' else r'/app/contract/logs'
LOG_FILE_PATH = LOG_BASE_PATH + '//log.txt'

'''
错误信息展示
'''
PRINT_TRACEBACK_OPTION = True

'''
长文本的拆分
'''
LONG_CONTENT_SPLIT_OPTION = True  # 是否对长文本进行拆分
LIMIT_PARAGRAPH = 2000  # 段落的最长文本
SPLIT_CONTENT_DTYPE = 'recursive'  # spacy, recursive

# 选用的 Embedding 名称
EMBEDDING_MODEL_NAME = "bge-large-zh-v1.5"
EMBEDDING_MODEL_PATH = os.path.join(MODEL_BASE_PATH, EMBEDDING_MODEL_NAME)
EMBEDDING_API_KEY = 'none'  # 用的网络接口的api key
EMBEDDING_DTYPE = 'local'  # 是否用本地模型 local or network

# 日志地址
LOG_LLM_SERVER_DIR = r'D:\\contract\\logs\\llm' if platform.system() == 'Windows' else r'/app/contract/logs/llm'
create_file(LOG_LLM_SERVER_DIR)

'''
python venv 地址信息
'''

PYTHON_VENV = os.path.join(sys.prefix, 'bin/python')

'''
启动方式
'''
CONTRACT_MODEL_DEVICE = 'cuda:0'
ERROR_CORRECTION_MODEL_DEVICE = 'cuda:0'
LLM_CUDA_VISIBLE_DEVICES = '1'

'''
大模型最大tokens
'''
MAX_TOKENS = 8000

'''
大模型最长的字符串数量 8192
'''
MAX_LEN_TEXT = int(MAX_TOKENS * 0.8)

TEMPERATURE = 0